#ifndef F_CASgiDriverC_h
#define F_CASgiDriverC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCASgiDriverSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SNoAnswer, SRxBurst, SRxDataBurst, SAnswer, STxBurst, STxDataBurst };


	friend class CASgiDriver;

	CASgiDriver &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SGIGround;

	enum edroomStateId{I, Listening};

	enum IdTrans{Init, SendSignal, SendSignal_NotAnswer, SendSignal_MessageReceived, SendData, SendData_NotAnswer, SendData_MessageReceived,  EDROOMMEMORIA };

	//Constantes



	//Variables

	uint16_t &VByteNumber;
	bool_t &VMessageCompleted;
	byte_t *VStringDataBurst;


	//Pool

	class CEDROOMPOOLCDBurst:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDBurst(TEDROOMUInt32 elemCount,CDBurst *pMem, TEDROOMBool *pMarks);
		CDBurst	* AllocData();
	};
	CEDROOMPOOLCDBurst	& EDROOMPoolCDBurst;
	class CEDROOMPOOLCDDataBurst:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDDataBurst(TEDROOMUInt32 elemCount,CDDataBurst *pMem, TEDROOMBool *pMarks);
		CDDataBurst	* AllocData();
	};
	CEDROOMPOOLCDDataBurst	& EDROOMPoolCDDataBurst;


	// CONSTRUCTORES

	EDROOMTopContext (CASgiDriver &act, uint16_t & EDROOMpVarVByteNumber, bool_t & EDROOMpVarVMessageCompleted, byte_t * EDROOMpVarVStringDataBurst, CEDROOMPOOLCDBurst & EDROOMpPoolCDBurst, CEDROOMPOOLCDDataBurst & EDROOMpPoolCDDataBurst );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	void	FBuildUpBurst();

	void	FCheckBytesReceived();

	void	FGetData();

	void	FInit();

	void	FNotAnswer();

	void	FSendBurstToGround();

	void	FSendDataBurstToGround();

	void	FWaitToResponse();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	uint16_t VByteNumber;
	bool_t VMessageCompleted;
	byte_t VStringDataBurst[8224];


	//Pools

	CEDROOMPOOLCDBurst	EDROOMPoolCDBurst;
	CEDROOMPOOLCDDataBurst	EDROOMPoolCDDataBurst;


public:

	// CONSTRUCTOR

	EDROOMTopState (CASgiDriver &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Listening

	// ***********************************************************************



	TEDROOMTransId EDROOMListeningllegada();

};


#endif
